#include"Stack.h"


void SQInit(StackQueue* ps)
{
	assert(ps);
	ps->data = NULL;
	ps->top = 0;
	ps->capacity = 0;
}
void SQDestroy(StackQueue* ps)
{
	assert(ps);
	free(ps->data);
	ps->data = NULL;
	ps->top = 0;
	ps->capacity = 0;
}
void SQPush(StackQueue* ps, STDataType x)
{
	assert(ps);
	if (ps->top == ps->capacity)
	{
		int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
		STDataType* ptr = (STDataType*)realloc(ps->data, sizeof(STDataType) * newCapacity);
		if (ptr == NULL)
		{
			perror("SQPush->realloc failed");
			exit(-1);
		}
		ps->data = ptr;
		ps->capacity = newCapacity;
	}
	ps->data[ps->top] = x;
	ps->top++;
}
void SQPop(StackQueue* ps)
{
	assert(ps);
	assert(ps->top > 0);
	--ps->top;
}
STDataType SQTop(StackQueue* ps)
{
	assert(ps);
	assert(ps->top > 0);
	return ps->data[ps->top - 1];
}
bool SQEmpty(StackQueue* ps)
{
	assert(ps);
	return ps->top == 0;
}
int SQSize(StackQueue* ps)
{
	assert(ps);
	return ps->top;
}

